﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartHotel.BLL;
using SmartHotel.DAL;
using SmartHotel.Model;

namespace SmartHotel.WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
       public ProductController(ProductBLL productBLL)
        {
            ProductBLL = productBLL;
        }

        public ProductBLL ProductBLL { get; }

        /// <summary>
        /// 添加商品的数据访问层方法  
        /// </summary>
        /// <param name="product">商品对象</param>
        /// <returns></returns>
        [HttpPost]
        public int AddProduct(Product product)
        {
            return ProductBLL.AddProduct(product);
        }
        /// <summary>
        /// 根据id查找商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Product GetProductById(int id)
        {

            return ProductBLL.GetProductById(id);
        }
        [HttpPut]
        public int UpdateProduct(Product product)
        {
            return ProductBLL.UpdateProduct(product);
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DeleteProduct(int id)
        {
            return ProductBLL.DeleteProduct(id);
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public int LogicDelte(int id)
        {
            return ProductBLL.LogicDelte(id);
        }
        [HttpGet]
        public MyPage<Product> GetProductPages(int index, int size, 
            string? Name, DateTime? beginTime, DateTime? endTime)
        {
            int count = 0; //重点
            return ProductBLL.GetProductPages(index, size, out count, Name, beginTime, endTime);
        }

        [HttpGet]
        public MyPage<Product> GetProductFenYe(int index, int size,string? name)
        {
            int count = 0;
            return ProductBLL.GetProductFenYe(index, size, out count, name);
        }

        [HttpPost]
        public int DuiHuan(string userName, int productId)
        { 
            return ProductBLL.DuiHuan(userName, productId);
        }
      }
}
